﻿
using ECharts.Net;
using Microsoft.Web.WebView2;
using System;
using System.IO;
using System.Windows;
using ECharts.Net.Wpf; 


namespace EChartsInWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            InitializeWebView(); 
        }

        private async void InitializeWebView()
        {
           // 1.html形式
            await webView.EnsureCoreWebView2Async(null);
            var htmlFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "chart.html");
            webView.Source = new Uri(htmlFilePath);

            // 2.后台写options的形式
            var option = new Option
            {
                Title = new Title
                {
                    Text = "ECharts 示例"
                },
                Tooltip = new Tooltip
                {
                    Trigger = TooltipTrigger.Axis
                },
                XAxis = new XAxis
                {
                    Data = new List<string>() { "衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋","袜子" }
                },
                YAxis = new YAxis(),
                Series = new List<Series>()
                {
                    new Series
                    {
                        Name = "品类",
                        Type = SeriesType.Bar,
                        Data = new object[] { 10, 52, 200, 334, 390, 330, 220 }
                    }
                }
            }; 
            chart.ChartOption = option;

        }

      
    }
}